<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>目录扫描任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>

    <link rel="stylesheet" href="{{ url_for('static', filename='css/font.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/xadmin.css') }}">
    <script src="{{ url_for('static', filename='lib/layui/layui.js') }}" charset="utf-8"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='js/xadmin.js') }}"></script>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">

                <div class="layui-card-header">
                    <button class="layui-btn"
                            onclick="xadmin.open('添加任务','{{ url_for('admin.initiative_add') }}',800,600)">
                        <i class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>

                            <th>序列</th>
                            <th>父级任务</th>
                            <th>攻击类型</th>
                            <th>状态</th>
                            <th>进度</th>
                            <th>高危漏洞</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for i in datas.data_list %}
                            <tr>
                                <td>{{ loop.index }}</td>
                                <td>{{ i.parent_name }}</td>
                                <td>{{ i.hack_type }}</td>
                                <td>{{ i.status }}</td>
                                <td>{{ i.progress }}</td>
                                <td>{{ i.live_host }}</td>
                                <td>{{ i.create_date.strftime("%Y-%m-%d %H:%M:%S") }}</td>
                                {% if i.end_time == "Null" %}
                                    <td>Null</td>

                                {% else %}
                                    <td>{{ i.end_time.strftime("%Y-%m-%d %H:%M:%S") }}</td>
                                {% endif %}

                                <td class="td-manage">
                                    <a title="导出" onclick="tasks_export(this,'{{ i.id }}')" href="javascript:;">
                                        <i class="layui-icon">&#xe63c;</i></a>
                                    <a title="删除" onclick="tasks_del(this,'{{ i.id }}')" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i></a>
                                </td>
                            </tr>

                        {% endfor %}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                            <ul class="pagination">
                                {% if datas.show_status == 1 %}
                                    <li><a href="{{ url_for('admin.ports') }}?p=1">首页</a></li>
                                    <li><a href="{{ url_for('admin.ports') }}?p={{ datas.p - 1 }}">上一页</a></li>
                                {% endif %}
                                {% for li in datas.page_list %}
                                    {% if li == datas.p %}
                                        <li class="active"><span>{{ li }}</span></li>
                                    {% else %}
                                        <li><a href="{{ url_for('admin.ports') }}?p={{ li }}">{{ li }}</a></li>
                                    {% endif %}
                                {% endfor %}
                                {% if datas.p < datas.page_total %}
                                    <li class=''><a href="{{ url_for('admin.ports') }}?p={{ datas.p + 1 }}">下一页</a>
                                    </li>
                                    <li class=''><a
                                            href="{{ url_for('admin.ports') }}?p={{ datas.page_total }}">尾页</a>
                                    </li>
                                {% endif %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>layui.use(['laydate', 'form'],
    function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

/*内容-导出*/
function tasks_export(obj, id) {
    var csrf_token = "{{ csrf_token() }}";

    $.ajaxSetup({
        beforeSend: function (xhr, settings) {
            if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrf_token);
            }
        }
    });


    var _data = {
        "task_id": id,
        'action': "export",
    };

    $.ajax({
        type: 'POST',
        data: _data,
        url: "{{ url_for('admin.initiative_controller') }}",
        dataType: 'json',
        success: function (data) {
            if (data.status == 200) {

                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000,
                }, function () {
                    window.location.reload();
                });

            } else {
                layer.msg(data.msg, {
                    icon: 2,
                    time: 1000,
                }, function () {
                    window.location.reload();
                });

            }
        }
    });
}


/*用户-删除*/
function tasks_del(obj, id) {
    layer.confirm('确认要删除吗？',
        function (index) {
            //CSRF的固定写法
            var csrf_token = "{{ csrf_token() }}";

            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader("X-CSRFToken", csrf_token);
                    }
                }
            });


            var _data = {
                "task_id": id,
                'action': "delete",
            };

            $.ajax({
                type: 'POST',
                data: _data,
                url: "{{ url_for('admin.initiative_controller') }}",
                dataType: 'json',
                success: function (data) {
                    if (data.status == 200) {

                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.location.reload();
                        });

                    } else {
                        alert(data.msg, 0);

                    }
                }
            });

        });
}


</script>

</html>